package com.ch.http.v1.impl;

import com.ch.http.v1.HttpServletRequest;
import com.ch.http.v1.HttpServletResponse;
import com.ch.http.v1.HttpSession;

import javax.servlet.annotation.WebServlet;
import java.io.PrintWriter;

@WebServlet("/session.s")
public class SessionServlet extends HttpSessionImpl {

    public void doGet(HttpServletRequest request, HttpServletResponse response){
        HttpSession session = request.getSession();
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();

        //验证会话中的数据
        Object sname = session.getAttribute("name");

        out.append("<h1>").append(""+sname).append("<h1>");

        //存入数据到会话
        String name = request.getParameter("name");
        if(name != null){
            session.setAttribute("name",name);
        }
    }
}
